package org.lanqiao.sjx.dao.impl;

import java.sql.SQLException;
import java.util.List;

import javax.sound.midi.MidiDevice.Info;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.lanqiao.bean.Education;
import org.lanqiao.bean.Work;
import org.lanqiao.sjx.dao.WorkDao;
import org.lanqiao.tools.BaseDao;

import com.sun.org.apache.bcel.internal.generic.NEW;

public class WorkImpl extends BaseDao implements WorkDao{

	@Override
	public Integer insertWork(Work info) {
		String sql="insert into work (userId,compName,jobName,startYear,startMonth,endYear,endMonth,date) "
				+ "values(?,?,?,?,?,?,?,Now())";
		try {
			return query.update(sql,info.getUserId(),info.getCompName(),info.getJobName(),info.getStartYear(),info.getStartMonth(),info.getEndYear(),info.getEndMonth());
		} catch (SQLException e) {			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer deleteWork(Integer id,Integer userId) {
		String sql="delete from work where id=? and userId=?";
		try {
			return query.update(sql,id,userId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<Work> selectWork(Integer userId) {
		String sql="select * from work where userId=?";
		try {
			return query.query(sql, new BeanListHandler<Work>(Work.class),userId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer updateWork(Work info) {
		String sql="update  work set compName=?,jobName=?,startYear=?,startMonth=?,endYear=?,endMonth=? where id=?";
		try {
			System.out.println(info.toString());
			return query.update(sql,info.getCompName(),info.getJobName(),info.getStartYear(),info.getStartMonth(),info.getEndYear(),info.getEndMonth(),info.getId());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer getCountWork() {
		// TODO Auto-generated method stub
		return null;
	}

}
